package cur.nature.admin.controller;

import cur.nature.admin.common.MessageUtil;
import cur.nature.admin.model.vo.Admin_DictVO;
import cur.nature.admin.service.Admin_DictService;
import cur.nature.framework.mvc.base.BaseAPI;
import cur.nature.framework.mvc.crud.CrudController;
import cur.nature.tinyorm.core.bean.PageBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通用字典表 Controller
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-09 16:14:19
 */
@Tag(name = "通用字典 接口")
@RestController
@RequestMapping("admin/v1/api/Admin_Dict")
public class Admin_DictController extends CrudController<Admin_DictService> {
    public Admin_DictController(Admin_DictService baseService) {
        super(baseService);
    }

    @Operation(summary = "查询 通用字典表")
    @PostMapping("/list")
    public PageBean<Admin_DictVO> list(@Valid @RequestBody Admin_DictVO.list_Param param) throws Exception {
        PageBean<Admin_DictVO> list = getService().list(param);
        return list;
    }

    @Operation(summary = "更新 通用字典表")
    @PostMapping("/operate")
    public BaseAPI.SaveResult<Admin_DictVO> save(@Valid @RequestBody List<Admin_DictVO> param) throws Exception {
        int rows = getService().saveList(param);
        BaseAPI.SaveResult result = new BaseAPI.SaveResult();
        result.setRows(rows);
        result.setObject(rows == 0 ? null : param);
        return result;
    }

    /**
     * 用于测试国际化
     * @return
     */
    @Operation(summary = "测试国际化")
    @GetMapping("/testLocalize")
    public BaseAPI.SaveResult<String> testLocalize() {
        String message = MessageUtil.getMessage("greeting.message");
        BaseAPI.SaveResult result = new BaseAPI.SaveResult();
        result.setObject(message);
        return result;
    }

}

